<script setup>
import { ref, getCurrentInstance, onMounted } from "vue"

const { proxy } = getCurrentInstance()

//这个tableData是假数据，等会我们使用axios请求mock数据
const tableData = ref([])
const tableLabel = ref({
  name: "课程",
  todayBuy: "今日购买",
  monthBuy: "本月购买",
  totalBuy: "总购买",
})

const countData = ref([])

const getTableData = () => {
  proxy.$api.getTableData().then((res) => {
    tableData.value = res.data
  })
}
const getCountData = () => {
  proxy.$api.getCountData().then((res) => {
    countData.value = res.data
  })
}
onMounted(() => {
  getTableData()
  getCountData()
})
</script>

<template>
  <el-row class="home" :gutter="20">
    <el-col :span="8" style="margin-top: 20px">
      <el-card shadow="hover">
        <div class="user">
          <img src="../assets/images/user.jpg" class="user" />
          <div class="user-info">
            <p>Admin</p>
            <p>超级管理员</p>
          </div>
        </div>

        <div class="login-info">
          <p>
            上次登录时间：
            <span>2022-7-11</span>
          </p>
          <p>
            上次登录IP：
            <span>北京</span>
          </p>
        </div>
      </el-card>

      <el-card shadow="hover" class="table">
        <el-table :data="tableData">
          <el-table-column v-for="(val, key) in tableLabel" :key="key" :prop="key" :label="val"></el-table-column>
        </el-table>
      </el-card>
    </el-col>
    
    <el-col :span="16" style="margin-top: 20px">
      <div class="num">
        <el-card v-for="(item, index) in countData" :key="index" shadow="hover">
          <div style="display: flex; align-items: center;">
            <component :is="item.icon" class="icons" :style="{ backgroundColor: item.color }"></component>
            <div class="detail">
              <div class="num">￥{{ item.value }}</div>
              <div>{{ item.name }}</div>
            </div>
          </div>
        </el-card>
      </div>
    </el-col>
  </el-row>
</template>



<style scoped lang="less">
.home {
  height: 100%;
  overflow: hidden;
  .user {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #ccc;
    margin-bottom: 20px;
    img {
      width: 150px;
      height: 150px;
      border-radius: 50%;
      margin-right: 40px;
    }
  }
  .login-info {
    p {
      line-height: 30px;
      font-size: 14px;
      color: #999;
      span {
        color: #666;
        margin-left: 60px;
      }
    }
  }
  .table {
    margin-top: 20px;
  }
  .num {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .el-card {
      width: 32%;
      margin-bottom: 20px;
    }
    .icons {
      width: 80px;
      height: 80px;
      font-size: 30px;
      text-align: center;
      line-height: 80px;
      color: #fff;
    }
    .detail {
      margin-left: 15px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      .num {
        font-size: 30px;
        margin-bottom: 1;
      }
    }
  }
}
</style>